import { join } from 'path';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ServeStaticModule } from '@nestjs/serve-static';
import { MongooseModule } from '@nestjs/mongoose';
import config from './utils/configuration';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PayModule } from './views/payment/payment.module';
import { UserModule } from './views/user/user.module';
import { AuthModule } from './views/auth/auth.module';
import { OrderModule } from './views/order/order.module';
import { StationModule } from './views/station/station.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      load: [config],
      isGlobal: true
    }),
    ServeStaticModule.forRoot({
      rootPath: join(__dirname, '..', 'public'), //指定静态文件的根目录
      serveRoot: '/static', // 设置URL访问的前缀,默认为空字符串，即访问静态文件时不需要加前缀（例如：http://localhost:3000/cat.jpeg）
      serveStaticOptions: {
        // 设置选项，例如：禁止缓存等
        cacheControl: true
      }
    }),
    MongooseModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        uri: configService.get<Config.Database>('database').uri
      })
    }),
    PayModule,
    UserModule,
    AuthModule,
    OrderModule,
    StationModule
  ],
  controllers: [AppController],
  providers: [AppService]
})
export class AppModule {}
